<?php
/*
 * @project CreativeFramework
 * @version <#RELEASE_VERSION#>
 * @license GNU Lesser General Public License
 * @author Jimmie Lin
 */

class Debug {
	function __construct() {
		$this->debugmsg = array(); // Debug messages will be written in later
	}
	
	/**
	 * writeLog
	 * Write a log entry into the runtime log. IN_DEV is checked. True if IN_DEV, otherwise false
	 * @param string message
	 * @param string type="Application"
	 * @return bool
	 */
	function writeLog($message, $type = "Application") {
		// There are various types of log messages.
		// If you aren't modding the core, usually
		// you would just supply message and the type
		// will be automatically "Application"-level.
		// If you are using a hook, then use type="Hook"
		// There are the levels Core, Application, Hook
		if(IN_DEV) {
			$this->debugmsg[] = "Written by <b>{$type}</b> on ".microtime(true).": ".$message."<br />";
			return true;
		}
		else return false;
	}
	
	/**
	 * getLogCount
	 * Gets the length (amount) of logs currently stored up to the function call.
	 * @return int
	 */
	function getLogCount() {
		return count($this->debugmsg);
	}
	
	/**
	 * getLog
	 * Get the logs and also write in a debug log entry with the SHUTDOWN message
	 * @return string
	 */
	function getLog() {
		$this->writeLog("Debug Class <span style='color:red'>SHUTDOWN</span> - Log Fetched", "Core");
		return implode("", $this->debugmsg);
	}
	
	/**
	 * logStub
	 * Log a stub. Use logstub(__CLASS__, __METHOD__, __FILE__, __LINE__, __FUNCTION__), ALWAYS!
	 * @param string class
	 * @param string method
	 * @param string file
	 * @param mixed line
	 * @param mixed function
	 */
	function logStub($class, $method, $file, $line, $function) {
		$this->writeLog("<b>Stub Declared:</b> Method $method (Line $line on file $file, function $function)", "Unknown");
	}
		
}
